package com.cuz.hot100;

public class Q35searchInsert {
    public static void main(String[] args) {
        int[] ints = {1,3};
        System.out.println(searchInsert1(ints, 3));
    }
    public static int searchInsert1(int[] nums, int target) {
        if (nums == null || nums.length == 0) {
            return 0;
        }
        if (nums[0] >= target) {
            return 0;
        }
        if (nums[nums.length - 1] < target) {
            return nums.length;
        }
        int left = -1;
        int right = nums.length;
        while (left + 1 != right) {
            int mid = (left + right) / 2;
            if (nums[mid]==target){
                return mid;
            }
            if (nums[mid] < target) {
                left = mid;
            } else {
                right = mid;
            }
        }
        return left + 1;
    }

}
